﻿
namespace AB.ServiceDirectory.Dao
{
    using System.Linq;
    using Entities;
    using Commons;

    /// <summary>
    /// UserDao Class
    /// </summary>
    public static class UserDao
    {
        /// <summary>
        /// Validates the user.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public static ValidateUserResult ValidateUser(string account, string password)
        {
            var user = DB.Context.Users.FirstOrDefault(a => a.Account == account && a.Password == password);
            var result = ValidateUserResult.Success;

            if (user == null)
            {
                result = ValidateUserResult.Fail;
            }
            else if (!user.IsActive)
            {
                result = ValidateUserResult.IsInactive;
            }

            return result;
        }

        /// <summary>
        /// Gets the name of the user by account.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <returns></returns>
        public static User GetUserByAccountName(string account)
        {
            var user = DB.Context.Users.FirstOrDefault(a => a.Account.Equals(account));
            return user;
        }
    }
}
